package chat;
import java.sql.*;

public class  chatreg{
  String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
  String sConnStr = "jdbc:odbc:chatreg";
  Connection conn = null;
  ResultSet rs = null;
  Statement stmt;

  public chatreg() {
    try {
      Class.forName(sDBDriver); 
      conn = DriverManager.getConnection(sConnStr,"","");
      stmt = conn.createStatement();
    }catch(java.lang.ClassNotFoundException e) {
       System.err.println("chatreg(): " + e.getMessage());
    }catch(java.sql.SQLException e){
       System.err.println("chatreg(): " + e.getMessage());
    }
  }

  public ResultSet executeQuery(String sql) {
    rs = null;
    try {
      if(conn==null){
         conn = DriverManager.getConnection(sConnStr,"","");
         stmt = conn.createStatement();
      }
      rs = stmt.executeQuery(sql);
    }catch(SQLException e) {
      System.err.println(e.getMessage());
    }
    return rs;
  }
  
  public boolean executeUpdate(String sql) {
    boolean success = false;
    try {
      if(conn==null){
         conn = DriverManager.getConnection(sConnStr,"","");
         stmt = conn.createStatement();
      }
      stmt.executeUpdate(sql);
      success=true;
    }catch(SQLException e) {
      success=false;
    }
    return success;
  }

  public void close(){
    try{
      if(!conn.isClosed())
         conn.close();
         conn=null;
    }catch(SQLException el){
      el.printStackTrace(); 
    }
  } 
}
